import { Engine, Scene, Vector3, HemisphericLight, MeshBuilder, ArcRotateCamera } from '@babylonjs/core';

/**
 * 创建一个包含简单立方体的Babylon场景
 * @param canvas 渲染的canvas元素
 * @returns 创建的场景实例
 */
export function createScene(canvas: HTMLCanvasElement): Scene {
  // 创建引擎
  const engine = new Engine(canvas, true);
  
  // 创建场景
  const scene = new Scene(engine);
  
  // 创建相机
  const camera = new ArcRotateCamera('camera', -Math.PI / 2, Math.PI / 2.5, 3, new Vector3(0, 0, 0), scene);
  camera.attachControl(canvas, true);
  
  // 创建光源
  const light = new HemisphericLight('light', new Vector3(0, 1, 0), scene);
  light.intensity = 0.7;
  
  // 创建简单立方体
  const box = MeshBuilder.CreateBox('box', { size: 1 }, scene);
  
  // 运行渲染循环
  engine.runRenderLoop(() => {
    scene.render();
  });
  
  // 处理窗口大小变化
  window.addEventListener('resize', () => {
    engine.resize();
  });
  
  return scene;
} 

/**
 * 创建一个包含球体的Babylon场景
 * @param canvas 渲染的canvas元素
 * @returns 创建的场景实例
 */
export function createSphereScene(canvas: HTMLCanvasElement): Scene {
  // 创建引擎
  const engine = new Engine(canvas, true);
  
  // 创建场景
  const scene = new Scene(engine);
  
  // 创建相机
  const camera = new ArcRotateCamera('camera', -Math.PI / 2, Math.PI / 2.5, 3, new Vector3(0, 0, 0), scene);
  camera.attachControl(canvas, true);
  
  // 创建光源
  const light = new HemisphericLight('light', new Vector3(0, 1, 0), scene);
  light.intensity = 0.7;
  
  // 创建球体
  const sphere = MeshBuilder.CreateSphere('sphere', { diameter: 1 }, scene);
  
  // 运行渲染循环
  engine.runRenderLoop(() => {
    scene.render();
  });
  
  // 处理窗口大小变化
  window.addEventListener('resize', () => {
    engine.resize();
  });
  
  return scene;
} 